function common_main(FilmUrl){
    $.get(
        FilmUrl+"html/header.html",
        function (data) {
            common_$header.html(data);
            let $div = $("div[class='main-navigation']");
               common_function_AddHref($div);
            common_function_AddTrabecula($div);
            common_function_search($div);
            let $branding = $("#branding");
            common_function_fillLogo($branding);
            let $UserORAdmin = $div.find("div[class='btn-group']");

            common_function_show_userORAdmin($UserORAdmin);
        },
        "html"
    )
    $.get(
        FilmUrl+"html/footer.html",
        function (data) {
            common_$footer.html(data);
        },
        "html"
    )
}

/**
 * 添加分类的链接
 *
 */
function common_function_AddHref($div){
        let $li =$div.find("ul[class='menu']").find("li");
        for(let i=0;i<$li.length;i++){
           let a = $li.eq(i).find("a").get(0);
           a.href = i===0
              ? FilmUrl+common_index
              : FilmUrl+common_review+"?type="+a.innerHTML;
        }
}

/**
 * 填充logo处的a标签
 * @param $branding
 */
function common_function_fillLogo($branding) {
    $branding.get(0).href=FilmUrl+common_index;
}
/**
 * 添加横条
 * @param $div
 */
function common_function_AddTrabecula($div) {
    let $li =$div.find("ul[class='menu']").find("li");

    if(common_type_byUrl==="false"){

        $li.eq(0).attr({class:"menu-item current-menu-item"});
        $li.not($li.eq(0)).attr({class:"menu-item"});
    }else {
        for(let i=1;i<$li.length;i++){
             let $a = $li.eq(i).find("a");
            if($a.html()===common_type_byUrl){
                $li.eq(i).attr({class:"menu-item current-menu-item"});
                $li.not($li.eq(i)).attr({class:"menu-item"});
                break;
            }
        }
    }
}
function common_function_search($div) {
    let $search = $div.parent().find("form");
    let $input = $search.find("input");
    $search.find("button").click(function () {

            if($input.val()===""){
                alert("请输入要搜索的内容");
                $search.get(0).action="#"
                return false;
            }else {

                $search.get(0).action=FilmUrl+common_search;
                return true;
            }
    })

}
function common_function_show_userORAdmin($userORAdmin) {
    //显示用户名字或管理员名字

    let userName = Cookies.get("UserName");
    let adminName = Cookies.get("AdminName");

    let $name = $userORAdmin.find("button[class='btn btn-danger']").find("a");
    let $list = $userORAdmin.find("ul[class='dropdown-menu']");
    let $list_a = $list.find("a");
    let account_name=userName!==undefined
                        ? "UserName" : adminName!==undefined
                            ? "AdminName" : "";
    $name.get(0).innerHTML= userName!==undefined
                                ? userName.substring(0,Math.min(userName.length,4)) :
                                 adminName!==undefined
                                     ? adminName.substring(0,Math.min(adminName.length,4)) : "其他";


    $list_a.get(0).innerHTML= userName!==undefined
                                    ? userName :
                                    adminName!==undefined ? adminName : "登录";
    $list_a.get(0).href= userName!==undefined
                            ? UserUrl :
                            adminName!==undefined ? "#" : UserUrl;
    $list_a.get(1).innerHTML= userName!==undefined
                                    ? "上传影片" :
                                    adminName!==undefined ? "上传影片" : "注册";
    $list_a.get(1).href=  userName!==undefined
                            ? FilmUrl+common_upFilm :
                            adminName!==undefined ? FilmUrl+common_upFilm : FilmUrl+common_SignIn;
    if(userName===undefined&&adminName===undefined){
        $list_a.eq(2).parent().attr({style: "display: none"});
    }else {
        $list_a.eq(2).parent().attr({style: "display: "});
    }
    $list_a.eq(2).click(function () {
        common_function_exit_account(account_name,this);
    })
}

/**
 * 退出账号
 * @param name
 * @param exit
 */
function common_function_exit_account(name,exit) {
    Cookies.remove(name);
    let newVar = Cookies.get(name);
    if(newVar!==undefined){
        alert("退出失败");
    }else {
        exit.href=FilmUrl;
        alert("退出成功");

    }

}